package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bp.domain.DrBayConsult;
import com.naiterui.ehp.bs.doctor.dao.IDrBayConsultDao;
import com.naiterui.ehp.bs.doctor.repository.IDrBayConsultRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AdDrBayConsultDaoImpl  implements IDrBayConsultDao {

    @Autowired
    private IDrBayConsultRepository drBayConsultRepository;

    @Override
    public void saveBatch(Long doctorId, String week, String everyTime) {
        if (StringUtils.isNoneBlank(week) && StringUtils.isNoneBlank(everyTime)) {
            String[] weekIndexs = week.split(",");
            List<DrBayConsult> list = new ArrayList<>();
            for (String index : weekIndexs) {
                DrBayConsult consult = new DrBayConsult();
                consult.setDoctorId(doctorId);
                consult.setWeekIndex(Integer.parseInt(index));
                consult.setWork(everyTime);
                list.add(consult);
            }
            drBayConsultRepository.save(list);
        }
    }

}
